//
//  LXUpLoadVideoViewController.m
//  cat
//
//  Created by imera on 16/4/1.
//  Copyright © 2016年 LX. All rights reserved.
//

#import "LXUpLoadVideoViewController.h"
#import "LXNavBarView.h"
#import "LXSearchTableViewCell.h"
#import "MoviePlayerViewController.h"

@interface LXUpLoadVideoViewController () <LXNavBarViewDelegate, UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, weak) UITableView *tableView;

@end

@implementation LXUpLoadVideoViewController

- (void)setVideoArr:(NSArray *)videoArr
{
    if (videoArr != nil) {
        _videoArr = videoArr;
        
        [self.tableView reloadData];
    }
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self initSubViews];
}

- (void)initSubViews
{
    /** 导航条 */
    LXNavBarView *navBarView = [[LXNavBarView alloc]init];
    navBarView.leftTitle = @"上传的视频";
    navBarView.myDelegate = self;
    navBarView.rightBtn.enabled = NO;
    navBarView.frame = CGRectMake(0, 20, self.view.frame.size.width, LXNavBarHeight);
    [self.view addSubview:navBarView];

    UITableView *tableView = [[UITableView alloc]init];
    tableView.frame = CGRectMake(0, 20 + LXNavBarHeight, self.view.frame.size.width, self.view.frame.size.height - 20 - LXNavBarHeight);
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.delegate = self;
    tableView.dataSource = self;
    self.tableView = tableView;
    [self.view addSubview:tableView];
}

#pragma mark - 自定义导航栏代理 
- (void)popCurrentViewController:(LXNavBarView *)navBarView
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - tableview代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.videoArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

- (LXSearchTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"Cell";
    
    LXSearchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[LXSearchTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.video = self.videoArr[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MoviePlayerViewController *videoPlay = [[MoviePlayerViewController alloc]init];
    videoPlay.video = self.videoArr[indexPath.row];
    [self presentViewController:videoPlay animated:YES completion:nil];
}

@end
